<?php
namespace models\repositories;
use Doctrine\ORM\EntityRepository;
use entities;
class ProcedureStepRepository extends EntityRepository {
	public function testIterate(){
		echo "<br>iterasi x";
	}
	
	public function findByUserProfiles($userProfiles, $arrProfile){
		$rsm = new \Doctrine\ORM\Query\ResultSetMapping;
		$rsm->addEntityResult('models\entities\ProcedureStep', 'u');
		$rsm->addFieldResult('u', 'id', 'id');
		$rsm->addFieldResult('u', 'nama', 'name');
	//	$rsm->addFieldResult('u', 'type', 'type');
	//	$rsm->addFieldResult('u', 'profile', 'profile');
		$arr= array();
		foreach ($userProfiles as $obj) {
			if (in_array($obj->getProfile()->getId(), $arrProfile)){
				$arr[] = $obj->getProfile()->getId();	
			}			
		}
		$profiles = implode(",", $arr);
		
		$query = $this->_em->createNativeQuery("select procedure_step.* from procedure_step 
													inner join profile ON procedure_step.profile = profile.id
													where profile.id in (".$profiles.")",$rsm);
		$str = $query->getResult();		
		
		//echo "<pre>";print_r($str);die();
		return $str;	
									
	}	
}

